<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html">
    <h:head>
        <title>Facelet Title</title>
        
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
        <script src="http://ajax.cdnjs.com/ajax/libs/json2/20110223/json2.js"></script>
        <script src="http://ajax.cdnjs.com/ajax/libs/underscore.js/1.1.6/underscore-min.js"></script>
        <script src="http://ajax.cdnjs.com/ajax/libs/backbone.js/0.3.3/backbone-min.js"></script>

        
    </h:head>
    <h:body>
        Hello from Facelets
        <br />
        <h:link outcome="welcomePrimefaces" value="Primefaces welcome page" />
        
        <button>Send an HTTP GET request to a page and get the result back</button>
        
    </h:body>
    
    <script>
        
        var UserModel = Backbone.Model.extend({ 
//            urlRoot: '/webresources/menu.user', 
            url: 'https://localhost:8181/WebApplication3/webresources/menu.drzava', 
            defaults: { 
                iddrzave: '10', 
                naziv: 'Novi record'
            } 
        }); 
        
    </script>
    
    <script>
        $(document).ready(function(){
          $("button").click(function(){
//            $.get("https://localhost:8181/WebApplication3/webresources/menu.drzava", 
//                function(data, status){
//                alert("Data: " + JSON.stringify(data) + "\nStatus: " + JSON.stringify(status));
//            });
                $.ajax({	//create an ajax request to load_page.php
                    type: "GET",
                    url: "https://localhost:8181/WebApplication3/webresources/menu.drzava",
//                    data: {
//                        alt: 'json-in-script'
//                    },
                    contentType: 'application/json; charset=utf-8',
                    dataType: "jsonp",	//expect html to be returned
                    success: function(msg){

                        alert( msg );
//                         alert( JSON.stringify( msg ) );   
//                        if(parseInt(msg)!=0)	//if no errors
//                        {
//                            $('#pageContent').html(msg);	//load the returned html into pageContet
//                            $('#loading').css('visibility','hidden');	//and hide the rotating gif
//                        }
                    },
                    jsonp: false,
                    jsonpCallback: "myJsonMethod",
                    error: function(e) { 
                        alert('Failed!' + JSON.stringify(e)); 
//                        alert('Failed!' + JSON.stringify(this)); 
                    },        
                    beforeSend: function(xhr, settings) { 
                         xhr.setRequestHeader('Authorization','Bearer ' + "token"); 
                    },
                    complete: function(cs1) {
                        alert(JSON.stringify( cs1 ));
                    }        

                });
                
                function myJsonMethod(data){
                    alert('myJsonMethod!' + JSON.stringify(data));
                };
                
//                
//                var requestNumber = JSONRequest.get(
//                    "https://localhost:8181/WebApplication3/webresources/menu.drzava",
//                    {
//                        user: "doctoravatar@yahoo.com",
//                        t: "vlIj",
//                        zip: 94089,
//                        forecast: 7
//                    },
//                    function (requestNumber, value, exception) {
//                        if (value) {
//                            alert('value!' + JSON.stringify(value)); 
//                            //processResponse(value);
//                        } else {
//                            alert('exception!' + JSON.stringify(exception)); 
//                            //processError(exception);
//                        }
//                    }
//                ); 

          });
        });
    </script>
    
</html>

